|
|
|
|
|
|
|
A dynaset does not automatically reflect additions or deletions made to the data by other users or other programs. A dynaset must be explicitly refreshed or re-created to show the changes. |
|
|
|
|
|
|
|
|
To set up a dynaset for use within a program, you must define the Recordset object with the Dim statement and then generate the dynaset using the OpenRecordset method with the dbOpenDynaset parameter. When you are creating a dynaset, the key part of the OpenRecordset method is the SQL statement that defines the records to be included, the filter condition, the sort condition, and any join conditions for linking data from multiple tables. |
|
|
|
|
|
|
|
|
The following code example illustrates how to create a dynaset by using a SQL statement that selects only specific records and that sorts the records in a specific order. These statements provide you access to the same information as you had by accessing the table directly with the previous code. The only difference is the type of recordset created. |
|
|
|
|
|
|
|
|
Dim MyDB As Database
Dim MyRS As Recordset
Dim sSQL As String
Set MyDB = OpenDatabase("biblio.mdb")
sSQL = "SELECT * FROM titles WHERE title <= 'B' ORDER BY title"
Set MyRS = MyDB.OpenRecordset(sSQL, dbOpenDynaset) |
|
|
|
|
|
|
|
|
If you want to include all records from one table in a dynaset in no particular order, you can omit the SQL statement and simply use the table name as follows: |
|
|
|
|
|
|
|
|
Set rsTitles = dbTest.OpenDatabase("titles") |
|
|
|
|
|
|
|
|
|
However, using a SQL statement is a good idea in case you want to modify the record selection criteria later.  |
|
|
|
|
|
|
|
|
|
|
When you create a dynaset, you can use any valid SQL statement that selects records. You can also specify options that affect the dynaset's behavior. Table 26.2 lists these options. |
|
|
|
|
| Table 26.2 Options Used to Modify the Access Mode of a Dynaset | | Option | Action | | dbDenyWrite | Prevents others in a multiuser environment from writing to the dynaset while you have it open | | dbReadOnly | Prevents you from making changes to the dynaset | | dbAppendOnly | Enables you to add new records but prevents you from reading or modifying existing records | | dbSQLPassThrough | Passes the SQL statement used to create the dynaset to an ODBC database server to be processed |
|
|
|